import request from "@/utils/request";
import type { AxiosPromise } from "axios";
import type { UnionPayLoginData, UnionPayRegisterData, UnionPayLoginResponse } from "./types";
import { useUserStore } from "@/stores/modules/user";
import { vueMetaEnv } from "@/settings";

class UnionPayApi {
  // 静默登录公众号.
  login(data: UnionPayLoginData): AxiosPromise<UnionPayLoginResponse> {
    data.tenant = useUserStore().user.tenant;
    data.appId = vueMetaEnv.APP_UNIONPAY_APPID;
    return request({
      url: "/v1/front/rbac/unionpay/auth",
      method: "post",
      data,
      headers: {
        Authorization: false
      }
    });
  }

  // 用户注册登录.
  register(data: UnionPayRegisterData): AxiosPromise<UnionPayLoginResponse> {
    data.tenant = useUserStore().user.tenant;
    data.appId = vueMetaEnv.APP_UNIONPAY_APPID;
    console.log(vueMetaEnv.APP_UNIONPAY_APPID, "=> vueMetaEnv.APP_UNIONPAY_APPID");
    return request({
      url: "/v1/front/rbac/unionpay/register",
      method: "post",
      data,
      headers: {
        Authorization: false
      }
    });
  }
}

const unionPayApi = new UnionPayApi();
export { unionPayApi };
